# -*- coding: utf-8 -*-
# @Time : 2022/1/6 10:19
# @Author : Limusen
# @File : login_page


from selenium import webdriver
from common.base_page import BasePage
from common.element_excel_utils import ElementExcelUtils


class LoginPage(BasePage):

    def __init__(self, driver):
        # 继承BasePage的方法,在此类中可以直接调用
        super().__init__(driver)
        # 将excel中的数据读取到elements中方便调用
        elements = ElementExcelUtils('login', 'login_page').get_element_info()
        self.login_button = elements["login_button"]
        self.user_name_input = elements["user_name_input"]
        self.password_input = elements["password_input"]
        self.switch_login_button = elements["switch_login_button"]

    def login_action(self, name, psw):
        # 方法一 直接整合
        self.click(self.login_button)
        self.input(self.user_name_input, name)
        self.input(self.password_input, psw)
        self.click(self.switch_login_button)

    # 方法二 分散写
    def click_main_login(self):
        self.click(self.login_button)

    def input_username(self, name):
        self.input(self.user_name_input, name)

    def input_password(self, pwd):
        self.input(self.password_input, pwd)

    def click_login(self):
        self.click(self.switch_login_button)


if __name__ == '__main__':
    driver = webdriver.Chrome()
    base = BasePage(driver)
    login = LoginPage(driver)

    base.open_url("http://shop.aircheng.com/")
    base.implicitly_wait(10)
    login.login_action("nswe", "111111")
